#include "stdafx.h"
#include "InputManager.h"

InputManager::InputManager()
{
	memset(currentState, INPUT_UP, sizeof(currentState));
	memset(previousState, INPUT_UP, sizeof(previousState));
}

InputManager::~InputManager()
{
}

void InputManager::Update(void)
{
	memcpy(previousState, currentState, sizeof(currentState));
}

void InputManager::UpdateState(unsigned char input, unsigned char state)
{
	currentState[input] = state;
}

// Input codes: http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
void InputManager::UpdateInputState(WPARAM wParam, unsigned char state)
{
	switch (wParam)
	{
	case 0x57:
		UpdateState(W_KEY, state);
		break;
	case 0x41:
		UpdateState(A_KEY, state);
		break;
	case 0x53:
		UpdateState(S_KEY, state);
		break;
	case 0x44:
		UpdateState(D_KEY, state);
		break;
	}
}

bool InputManager::InputDown(unsigned char input)
{
	return (currentState[input] == INPUT_DOWN);
}

bool InputManager::InputPressed(unsigned char input)
{
	return (currentState[input] == INPUT_DOWN) && (previousState[input] == INPUT_UP);
}

bool InputManager::InputReleased(unsigned char input)
{
	return (currentState[input] == INPUT_UP) && (previousState[input] == INPUT_DOWN);
}